from SelfSpyder import Jobspyder
from SelfSpyder import DataCleaning
from SelfSpyder import DataVisual
import tkinter as tk  # 使用Tkinter前需要先导入
 
#实例化object，建立窗口window
window = tk.Tk()
 
#给窗口的可视化起名字
window.title('前途无忧爬虫及可视化')
 
#设定窗口的大小(长 * 宽)
window.geometry('500x300')  # 这里的乘是小x
 

#放置标签
tk.Label(window, text='职位:', font=('Arial', 10)).place(x=100, y=1)
tk.Label(window, text='文件名:', font=('Arial', 10)).place(x=100, y=21)
tk.Label(window, text='爬取页数:', font=('Arial', 10)).place(x=100, y=41)
tk.Label(window, text='注意只有爬取数据之后，才可以清洗可视化!', font=('Arial', 12)).place(x=100,y=100)

#在图形界面上设定输入框控件entry框并放置
job = tk.Entry(window, show = None)#显示成明文形式
job.pack()
csv_name =  tk.Entry(window, show = None)
csv_name.pack()
page_num = tk.Entry(window, show = None)
page_num.pack()
# 定义两个触发事件时的函数
def Runspyder(): 

    var = job.get()
    var_one = csv_name.get()
    var_two = page_num.get()
    spyder = Jobspyder(var,var_one,var_two)
    spyder.run()

def dataclean():   
    var_one = csv_name.get()
    clean = DataCleaning(var_one)
    clean.main()

def datavisual():
    var_one = csv_name.get()
    visual = DataVisual(var_one)
    visual.read_csv()
    visual.jobcity()
    
# 创建并放置两个按钮分别触发两种情况
b1 = tk.Button(window, text='数据爬取', width=10,
               height=2, command = Runspyder)
b1.place(x=100,y=150)

b2 = tk.Button(window, text='数据清洗', width=10,
               height=2, command= dataclean)
b2.place(x=200,y=150)

b3 = tk.Button(window, text='数据可视化', width=10,
            height=2, command= datavisual)
b3.place(x=300,y=150)

# 主窗口循环显示
window.mainloop() 